<%--
  Created by IntelliJ IDEA.
  User: cgl
  Date: 2021/6/7
  Time: 10:49
  To change this template use File | Settings | File Templates.
--%>
<%@page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <base href="<%=basePath%>">

    <title>My JSP 'MyJsp.jsp' starting page</title>

    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
    <meta charset="UTF-8">
    <title>车票预定</title>
    <link rel="stylesheet" type="text/css" href="css/css1/ticket.css"/>
    <script src="js/js1/jquery-3.6.0.min.js"></script>
    <script>
        function exchangSite() {
            var siteStart = $("#siteStart").val();
            var siteEnd = $("#siteEnd").val();
            $("#siteStart").val(siteEnd);
            $("#siteEnd").val(siteStart);
            doSearch();
        }
        function sreachSite(trainId) {
            $.getJSON("train/getSite",
                {trainId: trainId},
                function (stopoverStationList){
                console.log(stopoverStationList)
                var ui=" "
                for (var i=0; i<stopoverStationList.length;i++) {
                     ui+= `<option value="id">` + stopoverStationList[i].siteOrder+`&nbsp;`+
                        stopoverStationList[i].site.siteName +`&nbsp;`+
                        stopoverStationList[i].arrivalTime   +
                        `&nbsp;</option>`
                }
                url="#"+trainId
                    console.log(url)
                $(url).html(ui);
            });
        }
        function checkEndTime(startTime,endTime){
            var starArr = startTime.split(':');
            var endArr = endTime.split(':');
            if(starArr[0]>endArr[0]){
                return 0;
            }
            if(starArr[0]==endArr[0]){
                if(starArr[1]>endArr[1]){
                    return 0;
                }
                if(starArr[1]==endArr[1]){
                    if(starArr[2]>=endArr[2]){
                        return 0;
                    }
                }
            }
            return 1;
        }

        function doSearch() {
            var siteStart = $("#siteStart").val();
            var siteEnd = $("#siteEnd").val();
            var startDate = $("#startDate").val();

            if (siteEnd == "") {
                alert("请输入终点站")

            }
            if (siteStart == "") {
                alert("请输入起始站")

            }
            if (startDate == "") {
                alert("请选择时间")

            }
            if(siteEnd!=""&&siteStart!=""&&startDate!=""){
            $.getJSON("train/getTrain", {
                siteStart: siteStart,
                siteEnd: siteEnd,
                startDate: startDate
            }, function (trainNumberList) {
console.log(trainNumberList)
                var ui=" "
                if(trainNumberList.length>0){
                for (var i=0; i<trainNumberList.length;i++){
                    var s=checkEndTime(trainNumberList[i].startTime,trainNumberList[i].destinationTime);
                    if(s==1) {
                        ui += `<table class="data-table"  cellspacing="0" cellpadding="0" width="70%"style="margin: 20px auto" >
                <inputtype="hidden" id="ycTrainId" name="ycTrainId" value=""/>
                        <tr class="data-col" height="30px" >
                         <td class="data-td"><span id="ustastion">` + siteStart + `</span>
                          <br class="data-td"/>` + trainNumberList[i].startTime + `</td>
                            <td class="data-td">` + trainNumberList[i].train.trainType.typeName + trainNumberList[i].train.trainName + `</td>
                             <td class="data-td">` + siteEnd + `
                        <br class="data-td"/>到达时间：` + trainNumberList[i].destinationTime + `</td>
                        <td class="data-td">商务：有
                        <td class="data-td">一等座：` + "有" + `</td>
                         <td class="data-td">二等座：` + trainNumberList[i].yesNo + `</td>
                         <td class="data-td"> <button class="searchbtn"onclick="sreachSite(` + trainNumberList[i].train.trainId + `)">查询经停站</button></td>
                          <td class="data-td" id="jtz1"> <select id="` + trainNumberList[i].train.trainId + `"></select></td>
                        <td class="data-td"><button id="str" onclick="yuDing(` + trainNumberList[i].trainNumberId + `)">预定</button></td>
                          </tr>
                            </table>`
                        if (trainNumberList[i].yesNo == "无") {
                            $("#str").disable = false;
                        }
                    }
                }
                $("#iframe").html(ui);
                }
                else{
                    alert("无该车次")
                }
            });}
        }
        function yuDing2(trainNumber){
            alert(trainNumber)
        }

        function yuDing(trainNumberId) {
            var siteStart = $("#siteStart").val();
            var siteEnd = $("#siteEnd").val();
            var startDate = $("#startDate").val();
            var url = "order/"+siteStart  +"/"+siteEnd+"/"+  trainNumberId+ "/"+startDate+"/trainOrderInfo";
            location = url;
        }




        function exchangeSreach() {
            var siteStart = $("#siteStart").val();
            var siteEnd = $("#siteEnd").val();
            var startDate = $("#startDate").val();

            if (siteEnd == "") {
                alert("请输入终点站")
                siteEnd = "!"
            }
            if (siteStart == "") {
                alert("请输入起始站")
                siteStart = "!"
            }
            if (startDate == "") {
                alert("请选择时间")
                startDate = "!!!!!!!!!!!!"
            }
            $.getJSON("train/getexchangeTrainSreach", {
                siteStart: siteStart,
                siteEnd: siteEnd,
                startDate: startDate
            }, function (trainNumberList) {
                var ui = " "
                console.log(trainNumberList)
                for (var i=0; i<trainNumberList.length;i+=2){
                    ui = `<table class="data-table"  cellspacing="0" cellpadding="0" width="70%"style="margin: 20px auto" >

             <tr class="data-col" height="30px" >
            <td class="data-td">出发站:` + siteStart + `
              <br class="data-td"/>出发时间:` + trainNumberList[i].departureTime + `</td>
            <td class="data-td">车名` + trainNumberList[i].train.trainType.typeName + trainNumberList[i].train.trainName + `
            </td>
            <td class="data-td">中转站` + trainNumberList[i].middleName + `
                <br class="data-td"/>到达时间` + trainNumberList[i].destinationTime + `
                <br class="data-td"/>出发时间` + trainNumberList[i+1].startTime + `
            </td>
            <td class="data-td">车名:` + trainNumberList[i+1].train.trainType.typeName + trainNumberList[i+1].train.trainName + `</td>
            <td class="data-td">` + siteEnd + `
            <br class="data-td"/>到达时间` + trainNumberList[i+1].startTime + `</td>
             <td class="data-td">商务</td>
            <td class="data-td">一等座</td>
            <td class="data-td">二等座</td>
            <td class="data-td"> <button class="searchbtn"onclick="yuDing(id)">预定</button></td>
        </tr>

    </table>`
                }
                $("#iframe").html(ui);

            });

        }

        function yuDingExchange(id) {
            var url = "order/" + id + "/exchangeTrainOrderInfo";
            location = url;
        }
    </script>
</head>

<body>
<div class="bg">
    <br/>
    <!--标题栏-->
    <div class="head-frame">
        <div class="head-panel">
            <img src="img/logo1.png"/>

            <div class="ctrl">
                <div class="my12306">我的12306</div>
                <div class="line"></div>
                <div id="welcome" class="font">欢迎</div>
                <div class="font" onclick="userExit()">注销</div>
            </div>
        </div>
    </div>
    <br/>
    <!--菜单栏-->
    <div class="menu-frame">
        <div class="menu-panel">
            <div class="menuValue" onclick="window.location.href ='login/Login'">首页</div>
            <div class="menuValue">车票预定</div>
            <div class="menuValue" onclick="window.location.href ='orderInfo.jsp'">订单信息</div>
            <div class="menuValue" onclick="window.location.href ='userInfo.jsp'">我的信息</div>
            <div class="menuValue">车站服务</div>
            <div class="menuValue">商旅服务</div>
            <div class="menuValue">出行指南</div>
        </div>
    </div>
    <br/>
    <!--输入栏-->
    <div class="input-frame">
        <div class="input-panel">
            <div class="ctrl">
                <div>
                </div>
                <div class="line"></div>

                <div class="destination">
                    <span> 起始车站:</span>
                    <input type="text" id="siteStart" name="siteStart"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <button class="searchbtn" onclick="exchangSite()">交换</button>
                </div>
                <div class="destination">
                    <span> 终点车站:</span>
                    <input type="text" id="siteEnd" name="siteEnd"/>
                </div>
                <div class="start-time">
                    <span>出发时间</span>
                    <input id="startDate" type="datetime-local"  class="start-time-field" type="text"/>
                </div>
                <button class="searchbtn" onclick="doSearch()">查询</button>

                <div class="line"></div>
                <div class="btn">
                    <button class="searchbtn" onclick="exchangeSreach()">换乘查询</button>
                </div>
            </div>
        </div>
    </div>
    <!--车票主界面-->
    <table class="data-table" cellspacing="0" cellpadding="0" width="70%"style="margin: 20px auto" >
        <thead>
        <tr class="data-col" height="30px">
            <div id="iframe">

            </div>
        </tr>
        </thead>
    </table>
    <br/><br/><br/><br/>
    <div class="other">
        <div class="o1">版权所有O2008-2018中国铁路信息科技有限责任公司中国铁道科学研究院集团有限公司</div>
        <div>京CP备15003716号-3[CP证150437号</div>
    </div>
</div>

</body>
</html>

